import solution.Solution_5sortandSearch;

/**
 * @author zhangmin
 * @create 2022-08-18 20:09
 */
public class Merge{
    /*public static void main(String[] args){
        int[] nums1=new int[]{1,3,5,7};
        int[] nums2=new int[]{2,4,6,8};
        int p1=0,p2=0;
        int[] res=new int[nums1.length+nums2.length];
        for(int i=0;i<res.length;i++){
            if(p1==nums1.length){
                res[i]=nums2[p2++];
            }else if(p2==nums2.length){
                res[i]=nums1[p1++];
            }else if(nums1[p1]<=nums2[p2]){
                res[i]=nums1[p1++];
            }else {
                res[i]=nums2[p2++];
            }
            System.out.print(res[i]+" ");
        }
    }*/
    public static class ListNode{
        int val;
        ListNode next;
        ListNode(){};
        ListNode(int val){
            this.val=val;
        }
        ListNode(int val,ListNode next){
            this.val=val;
            this.next=next;
        }
    }
    public static ListNode reverse(ListNode head){
        if(head==null||head.next==null) return head;
        ListNode nextNode=reverse(head.next);
        head.next.next=head;
        head.next=null;
        return nextNode;
    }
    static void printList(ListNode head){
        if(head==null) return;
        System.out.print(head.val+" ");
        printList(head.next);
    }
    public static void main(String[] args) {
        ListNode head=new ListNode(1,new ListNode(2,new ListNode(3)));
        ListNode node = reverse(head);
        printList(node);
    }
}
